home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / Blankers / MoireD / fMoire.c next >
Encoding:
C/C++ Source or Header  |  1993-05-24  |  9.9 KB  |  364 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  fMoire.c
  4. * Copyright        :  Free Software
  5. * Creation date    :  12-May-93
  6. * Translator       :  SAS/C 6.2
  7. * Compiler opts.   :  See Makefile
  8. *
  9. * Date       Rev  Author               Comment
  10. * ---------  ---  -------------------  ----------------------------------------
  11. * 12-May-93    0  Michael D. Bayne     Bouncing lines blanker module
  12. *
  13. *** DoRev End **/
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17.  
  18. #include <intuition/intuition.h>
  19. #include <intuition/screens.h>
  20.  
  21. #include <libraries/gadtools.h>
  22. #include <dos/dos.h>
  23. #include <graphics/gfxbase.h>
  24. #include <graphics/gfxmacros.h>
  25. #include <graphics/copper.h>
  26. #include <graphics/videocontrol.h>
  27. #include <hardware/custom.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/intuition_protos.h>
  31. #include <clib/graphics_protos.h>
  32. #include <clib/alib_protos.h>
  33. #include <clib/gadtools_protos.h>
  34. #include <clib/utility_protos.h>
  35.  
  36. #include <stdlib.h>
  37.  
  38. #include "Moire.h"
  39. #include "/defs.h"
  40.  
  41. extern struct Custom far custom;
  42.  
  43. struct mPrefObject {
  44.     LONG xSpeed, ySpeed, Trail, Cycle;
  45. };
  46.  
  47. #pragma libcall GfxBase LoadRGB32 372 9802
  48.  
  49. extern    int    RangeRand( int );
  50.  
  51.     struct    mPrefObject    nP;
  52. STATIC    const    UBYTE        VersTag[] = "\0$VER:Moire 1.1 (5.12.93)";
  53.         UBYTE        infoString[] = "Moire (Bouncing lines) Module";
  54.  
  55. void setMoirePrefs( void )
  56. {
  57.         GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, nP.Trail, 0L );
  58.         GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, nP.xSpeed, 0L );
  59.         GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, nP.ySpeed, 0L );
  60.     GT_SetGadgetAttrs( MoireGadgets[GD_CYCLE], MoireWnd, 0L, GTCY_Active, nP.Cycle, 0L );
  61. }
  62.  
  63. int OKClicked( void )
  64. {
  65.     return( QUIT );
  66. }
  67.  
  68. int CANCELClicked( void )
  69. {
  70.     return( CANCEL );
  71. }
  72.  
  73. int TRAILClicked( void )
  74. {
  75.     nP.Trail = MoireMsg.Code;
  76.     return( OK );
  77. }
  78.  
  79. int CYCLEClicked( void )
  80. {
  81.     nP.Cycle = MoireMsg.Code;
  82.     return( OK );
  83. }
  84.  
  85. int XSPEEDClicked( void )
  86. {
  87.     nP.xSpeed = MoireMsg.Code;
  88.     return( OK );
  89. }
  90.  
  91. int YSPEEDClicked( void )
  92. {
  93.     nP.ySpeed = MoireMsg.Code;
  94.     return( OK );
  95. }
  96.  
  97. int MoireVanillaKey( void )
  98. {
  99.     switch( MoireMsg.Code ) {
  100.     case 'o':
  101.         return( QUIT );
  102.     case 'c':
  103.         return( QUIT );
  104.     case 't':
  105.         GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, ++(nP.Trail) > 256 ?
  106.             nP.Trail = 256 : nP.Trail, 0L );
  107.         return( OK );
  108.     case 'T':
  109.         GT_SetGadgetAttrs( MoireGadgets[GD_TRAIL], MoireWnd, 0L, GTSL_Level, --(nP.Trail) < 1 ?
  110.             nP.Trail = 1 : nP.Trail , 0L );
  111.         return( OK );
  112.     case 'x':
  113.         GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, ++(nP.xSpeed) > 64 ?
  114.             nP.xSpeed = 64 : nP.xSpeed, 0L );
  115.         return( OK );
  116.     case 'X':
  117.         GT_SetGadgetAttrs( MoireGadgets[GD_XSPEED], MoireWnd, 0L, GTSL_Level, --(nP.xSpeed) < 1 ?
  118.             nP.xSpeed = 1 : nP.xSpeed, 0L );
  119.         return( OK );
  120.     case 'y':
  121.         GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, ++(nP.ySpeed) > 64 ?
  122.             nP.ySpeed = 64 : nP.ySpeed, 0L );
  123.         return( OK );
  124.     case 'Y':
  125.         GT_SetGadgetAttrs( MoireGadgets[GD_YSPEED], MoireWnd, 0L, GTSL_Level, --(nP.ySpeed) < 1 ?
  126.             nP.ySpeed = 1 : nP.ySpeed, 0L );
  127.         return( OK );
  128.     default:
  129.         return( OK );
  130.     }
  131. }
  132.  
  133. void defaults( UBYTE *prefData )
  134. {
  135.     (( struct mPrefObject * )prefData)->xSpeed = 16;
  136.     (( struct mPrefObject * )prefData)->ySpeed = 16;
  137.     (( struct mPrefObject * )prefData)->Trail = 64;
  138.     (( struct mPrefObject * )prefData)->Cycle = 0;
  139. }
  140.  
  141. void prefs( UBYTE *prefData )
  142. {
  143.     LONG    retval = OK;
  144.  
  145.     CopyMem( prefData, &nP, sizeof( struct mPrefObject ));
  146.     if( !SetupScreen() ) { if( !OpenMoireWindow()) {
  147.         CloseDownScreen();
  148.         setMoirePrefs();
  149.         while( 1 ) {
  150.             WaitPort( MoireWnd->UserPort );
  151.             retval = HandleMoireIDCMP();
  152.             if( retval == QUIT ) {
  153.                 CopyMem( &nP, prefData, sizeof( struct mPrefObject ));
  154.                 break;
  155.             }
  156.             if( retval == CANCEL ) break;
  157.         }
  158.         CloseMoireWindow();
  159.     } } else CloseDownScreen();
  160. }
  161.  
  162. void agaInit( struct Screen *Screen, LONG numCols )
  163. {
  164.     ULONG *agaTable, i, tPos;
  165.  
  166.     agaTable = AllocMem(( numCols*3 + 2 )*sizeof( ULONG ), MEMF_CLEAR );
  167.  
  168.     agaTable[0] = ( numCols<<16 );
  169.     agaTable[1] = agaTable[2] = agaTable[3] = 0;
  170.     tPos = 3;
  171.     for( i = 1; i < numCols/3+1; ++i ) {
  172.         agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
  173.         agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
  174.         agaTable[++tPos] = (0xFFFFFF);
  175.     }
  176.     for( i = 1; i < numCols/3+1; ++i ) {
  177.         agaTable[++tPos] = (0xFFFFFF);
  178.         agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
  179.         agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
  180.     }
  181.     for( i = 1; i < numCols/3+1; ++i ) {
  182.         agaTable[++tPos] = (0xFFFFFF)|((3*i)<<24);
  183.         agaTable[++tPos] = (0xFFFFFF);
  184.         agaTable[++tPos] = (0xFFFFFF)|((numCols-3*i)<<24);
  185.     }
  186.     agaTable[++tPos] = 0;
  187.  
  188.     LoadRGB32( &(Screen->ViewPort), agaTable );
  189. }
  190.  
  191. void ecsInit( struct Screen *Screen, LONG numCols )
  192. {
  193.     UWORD    Table6[] = { 0, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0,
  194.         0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B,
  195.         0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908,
  196.         0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00, 0x0F00, 0x0F20, 0x0E30, 0x0C50,
  197.         0x0B60, 0x0980, 0x0890, 0x06B0, 0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3,
  198.         0x00C5, 0x00B6, 0x0098, 0x006B, 0x005C, 0x003E, 0x002F, 0x020F, 0x030E,
  199.         0x050C, 0x060B, 0x0809, 0x0908, 0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 };
  200.     UWORD    Table5[] = { 0, 0x0F20, 0x0E30, 0x0C50, 0x0B60, 0x0980, 0x0890, 0x06B0,
  201.         0x05C0, 0x03E0, 0x02F0, 0x00F2, 0x00E3, 0x00C5, 0x00B6, 0x0098, 0x006B,
  202.         0x005C, 0x003E, 0x002F, 0x020F, 0x030E, 0x050C, 0x060B, 0x0809, 0x0908,
  203.         0x0B06, 0x0C05, 0x0E03, 0x0F02, 0x0F00 };
  204.     UWORD    Table4[] = { 0, 0x0E03, 0x0B06, 0x0909, 0x060B, 0x030E, 0x003E, 0x006B,
  205.         0x0099, 0x00B6, 0x00E3, 0x03E0, 0x06B0,    0x0990, 0x0B60, 0x0E30 };
  206.     UWORD    Table3[] = { 0, 0x0E00, 0x0770, 0x00E0, 0x0077, 0x000E,    0x0707 };
  207.     UWORD    Table2[] = { 0, 0x0E00, 0x00E0, 0x000E };
  208.     UWORD    Table1[] = { 0, 0x0FFF };
  209.     UWORD    *Table[6];
  210.  
  211.     Table[0] = Table1; Table[1] = Table2; Table[2] = Table3; Table[3] = Table4;
  212.     Table[4] = Table5, Table[5] = Table6;
  213.     
  214.     LoadRGB4( &(Screen->ViewPort), Table[Screen->BitMap.Depth-1], numCols );
  215. }
  216.  
  217. VOID newCopperList( LONG height, struct ViewPort *vp )
  218. {
  219.     #define NUMCOLORS 45
  220.  
  221.     struct    UCopList    *uCopList;
  222.     struct    TagItem    uCopTags[] = { { VTAG_USERCLIP_SET, 0L }, { VTAG_END_CM, 0L } };
  223.     register    USHORT    i, index = rand()%NUMCOLORS, spc;
  224.         UWORD    spectrum[] = {  0x0F00, 0x0E10, 0x0D20, 0x0C30, 0x0B40, 0x0A50, 0x0960, 0x0870, 0x0780, 0x0690,
  225.                 0x05A0, 0x04B0, 0x03C0, 0x02D0, 0x01E0, 0x00F0, 0x00E1, 0x00D2, 0x00C3, 0x00B4,
  226.                 0x00A5, 0x0096, 0x0087, 0x0078, 0x0069, 0x005A, 0x004B, 0x003C, 0x002D, 0x001E,
  227.                 0x000F, 0x010E, 0x020D, 0x030C, 0x040B, 0x050A, 0x0609, 0x0708, 0x0807, 0x0906,
  228.                 0x0A05, 0x0B04, 0x0C03, 0x0D02, 0x0E01 };
  229.     
  230.     if( uCopList = ( struct UCopList * )AllocMem( sizeof( struct UCopList ), MEMF_PUBLIC|MEMF_CLEAR )) {
  231.  
  232.         spc = height/NUMCOLORS;
  233.  
  234.         CINIT( uCopList, NUMCOLORS );
  235.  
  236.         for( i = 0; i<NUMCOLORS; ++i ) {
  237.             CWAIT( uCopList, i*spc, 0 );
  238.             CMOVE( uCopList, custom.color[1], spectrum[(i+index)%NUMCOLORS] );
  239.         }
  240.  
  241.         CEND( uCopList );
  242.  
  243.         Forbid();
  244.         vp->UCopIns = uCopList;
  245.         Permit();
  246.  
  247.         VideoControl( vp->ColorMap, uCopTags );
  248.  
  249.         RethinkDisplay();
  250.     }
  251. }
  252.  
  253. void blank( struct bMessage *Msg )
  254. {
  255.     struct    mPrefObject    *nP = ( struct mPrefObject * )Msg->prefData;
  256.     struct    Screen        *MoireScr;
  257.     struct     RastPort    *rp;
  258.  
  259.     ULONG    numCols, i, j, n, Trail = nP->Trail, xSpeed = nP->xSpeed, ySpeed = nP->ySpeed;
  260.     WORD    Wid, Hei, *cx1, *cy1, *cx2, *cy2, dx1, dy1, dx2, dy2;
  261.  
  262.     srand( VBeamPos());
  263.  
  264.     MoireScr = OpenScreenTags( 0l, SA_DisplayID, Msg->sMod, SA_Depth, Msg->sDep, SA_Quiet, TRUE,
  265.         SA_Overscan, OSCAN_STANDARD, TAG_DONE );
  266.  
  267.     rp = &( MoireScr->RastPort );
  268.     Wid = MoireScr->Width;
  269.     Hei = MoireScr->Height;
  270.  
  271.        numCols = (( 1 << MoireScr->BitMap.Depth )-1)%3 ? ( 1 << MoireScr->BitMap.Depth )-1 :
  272.         ( 1 << MoireScr->BitMap.Depth );
  273.  
  274.     if( numCols == 1 ) numCols = 2;
  275.  
  276.     cx1 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
  277.     cy1 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
  278.     cx2 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
  279.     cy2 = AllocMem( Trail*sizeof( UWORD ), MEMF_CLEAR );
  280.  
  281.     SetRGB4( &(MoireScr->ViewPort), 0, 0, 0, 0 );
  282.  
  283.     switch( nP->Cycle ) {
  284.     case 0:
  285.         if( MoireScr->BitMap.Depth > 6 ) agaInit( MoireScr, numCols );
  286.         else ecsInit( MoireScr, numCols );
  287.         break;
  288.     case 1:
  289.         SetRGB4( &(MoireScr->ViewPort), 1, rand()%15 + 1, rand()%15 + 1, rand()%15 + 1 );
  290.         break;
  291.         case 2:
  292.         SetRGB4( &(MoireScr->ViewPort), 1, 15, 15, 15 );
  293.         break;
  294.     case 3:
  295.         newCopperList( Hei, &( MoireScr->ViewPort ));
  296.         break;
  297.     }
  298.         
  299.     cx1[1] = RangeRand( Wid )+1; cy1[1] = RangeRand( Hei )+1;
  300.     cx2[1] = RangeRand( Wid )+1; cy2[1] = RangeRand( Hei )+1;
  301.     dx1 = RangeRand( xSpeed )+1; dy1 = RangeRand( ySpeed )+1;
  302.     dx2 = RangeRand( xSpeed )+1; dy2 = RangeRand( ySpeed )+1;
  303.     i = 0; j = 0;
  304.  
  305.     while(!(SetSignal(0,0) & SIGBREAKF_CTRL_C )) {
  306.         i = (i+1) % Trail;
  307.         n = (i+1) % Trail;
  308.         j = (j+1) % 255;
  309.  
  310.         if( !nP->Cycle ) SetAPen( rp, (j*(numCols-1))/255+1 );
  311.         else SetAPen( rp, 1 );
  312.  
  313.         if( cx1[i] >= Wid ) {
  314.             dx1 = -1*RangeRand( xSpeed )-1;
  315.             cx1[i] = Wid-1;
  316.         } else if( cx1[i] < 0 ) {
  317.             dx1 = RangeRand( xSpeed )+1;
  318.             cx1[i] = 0;
  319.         }
  320.         if( cx2[i] >= Wid ) {
  321.             dx2 = -1*RangeRand( xSpeed )-1;
  322.             cx2[i] = Wid-1;
  323.         } else if( cx2[i] < 0 ) {
  324.             dx2 = RangeRand( xSpeed )+1;
  325.             cx2[i] = 0;
  326.         }
  327.         if( cy1[i] >= Hei ) {
  328.             dy1 = -1*RangeRand( ySpeed )-1;
  329.             cy1[i] = Hei-1;
  330.         } else if( cy1[i] < 0 ) {
  331.             dy1 = RangeRand( ySpeed )+1;
  332.             cy1[i] = 0;
  333.         }
  334.         if( cy2[i] >= Hei ) {
  335.             dy2 = -1*RangeRand( ySpeed )-1;
  336.             cy2[i] = Hei-1;
  337.         } else if( cy2[i] < 0 ) {
  338.             dy2 = RangeRand( ySpeed )+1;
  339.             cy2[i] = 0;
  340.         }
  341.  
  342.         Move( rp, cx1[i], cy1[i] );
  343.         Draw( rp, cx2[i], cy2[i] );
  344.  
  345.         SetAPen( rp, 0 );
  346.         Move( rp, cx1[n], cy1[n] );
  347.         Draw( rp, cx2[n], cy2[n] );
  348.  
  349.         cx1[n] = cx1[i] + dx1;
  350.         cy1[n] = cy1[i] + dy1;
  351.         cx2[n] = cx2[i] + dx2;
  352.         cy2[n] = cy2[i] + dy2;
  353.     }
  354.  
  355.     SetSignal( 0L, SIGBREAKF_CTRL_C );
  356.  
  357.     FreeMem( cx1, Trail*sizeof( UWORD ) );
  358.     FreeMem( cx2, Trail*sizeof( UWORD ) );
  359.     FreeMem( cy1, Trail*sizeof( UWORD ) );
  360.     FreeMem( cy2, Trail*sizeof( UWORD ) );
  361.  
  362.     CloseScreen( MoireScr );
  363. }
  364.